package rsj.api.product;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import common.util.Assert;
import common.util.BoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.service.ProductService;
import rsj.table.SYS_PROD;
@RestController
public class DoProdSecUp extends BaseLink {
    @Autowired
    private  ProductService productService;

    @RequestMapping(value = "rsj_prod_secUp")
    public Box executeLink(Box in) {
        MapNode data = in.getMapNode("data");
        Assert.isNotNull(data, "没有收到要新增的信息！");
        checkParameter(data);

        int id = productService.sectionUpdateProd(data);
        if(id == 0){
            logger.error("没有保存任何信息！！！");
        }

        return BoxUtil.successBox(in, "保存成功");
    }

    private void checkParameter(MapNode data) {
        String Prod_Status = data.getValueDef(SYS_PROD.Prod_Status, "");
        Assert.isTrue("0".equals(Prod_Status) | "1".equals(Prod_Status), "产品状态只能是（0可用，1停用）");
        String Prod_Name=data.getValueDef(SYS_PROD.Prod_Name,"");
        Assert.isNotBlank(Prod_Name, "产品名称必填");
        String Prod_Type_Sid=data.getValueDef(SYS_PROD.Prod_Type_Fid,"");
        Assert.isNotBlank(Prod_Type_Sid, "产品一级类型参数必填");
        String Prod_Ctime=data.getValueDef(SYS_PROD.Prod_Ctime,"");
        Assert.isNotBlank(Prod_Ctime, "Prod_Ctime必填且非空！");
        String Prod_Endtime=data.getValueDef(SYS_PROD.Prod_Endtime,"");
        Assert.isNotBlank(Prod_Endtime, "Prod_Endtime必填且非空！");
        long Prod_Seq = Long.parseLong(data.getValue(SYS_PROD.Prod_Seq));
        Assert.isTrue(Prod_Seq > 0, "排序参数，Prod_Seq大于0");
        String Prod_Id = data.getValue(SYS_PROD.Prod_Id);
        Assert.isNotBlank(Prod_Id, "Prod_Id不能为空");
    }

}
